﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace HelperPrototype.TabPageControls
{
    public partial class SuaDinhDangMaPhieu : UserControl
    {
        public SuaDinhDangMaPhieu()
        {
            InitializeComponent();
        }

        private void SuaDinhDangMaPhieu_Load(object sender, EventArgs e)
        {
            loadData();
        }

        private void loadData()
        {
            _DB.DataClasses1DataContext dc = new _DB.DataClasses1DataContext();
            dgvDinhDang.Rows.Clear();
            foreach (_DB.DinhDangMaPhieu x in dc.DinhDangMaPhieus)
            {
                DataGridViewRow r = new DataGridViewRow();
                r.CreateCells(dgvDinhDang);
                r.Cells[0].Value = x.ID;
                r.Cells[1].Value = x.LoaiPhieu;
                r.Cells[2].Value = x.DinhDang;

                dgvDinhDang.Rows.Add(r);
            }
        }

        private void button2_Click(object sender, EventArgs e)
        {
            _DB.DataClasses1DataContext dc = new _DB.DataClasses1DataContext();
            foreach (_DB.DinhDangMaPhieu x in dc.DinhDangMaPhieus)
            foreach (DataGridViewRow r in dgvDinhDang.Rows)
            {
                if (x.ID == (int) r.Cells[0].Value)
                {
                    x.DinhDang = (string) r.Cells[2].Value;
                }
            }

            dc.SubmitChanges();
            MessageBox.Show("OK");
        }
    }
}
